import { list } from "../../../../api/groupBuy";
let app = getApp();
Component({
    lifetimes:{
        attached(){
            this.getList();
        },
    },
    properties: {
        info: {
          type: Object,
        }
    },

    data: {
        groupBuylist: [],
        pageSize: 10,
        pageNum: 1,
        name: "",
        productLoading:false,
        isBottom:false
    },
    methods: {
        gotobuy(e){
            let obj = {
                groupId: e.currentTarget.dataset.item.groupBuy.id,
                groupNum: e.currentTarget.dataset.item.groupBuy.groupNum,
                productId: e.currentTarget.dataset.item.productId,
                priceBox: e.currentTarget.dataset.item.price,
                productType: 'group',
            }
            wx.navigateTo({
                url: '/pages/goods/product/groupBuydetails?id=' + e.currentTarget.dataset.item.productId + '&obj=' + JSON.stringify(obj),
            })
        },
        getList() {
            let params = {
                pageNum: this.data.pageNum,
                pageSize: this.data.pageSize,
                mchId: app.globalData.mchId,
                type: 0,
                shopId: app.globalData.shopId,
            }
            list(params).then((res) => {
                res.data.data.forEach((item, index) => {
                    let params = JSON.parse(JSON.stringify(item))
                    delete params.itemList
                    item.itemList.forEach((itemList, itemListIndex) => {
                        item.itemList[itemListIndex].groupBuy = params
                    })
                })
                res.data.data.forEach(item => {
                    item.itemList.forEach(itemList => {
                        this.data.groupBuylist.push(itemList)
                    })
                })

                this.setData({
                    groupBuylist: this.data.groupBuylist
                })

                if (res.data.data.length < 10) {
                    this.data.productLoading = true
                    this.setData({
                        productLoading: this.data.productLoading,
                        isBottom: this.data.isBottom,
                    })
                    console.log(this.data.productLoading,"321321")
                }

            })
        },

        onReachBottom:function(){
            if(this.data.productLoading == false){
                wx.showLoading({
                    title: '加载中',
                })
                setTimeout(function () {
                    wx.hideLoading()
                }, 1000)
                this.data.pageNum += 1
                this.data.isBottom = true
                this.groupBuyclick()
            }
        },
    }
})
